#include <iostream>
#include <algorithm>

using namespace std;

int lis[128];
int rst[128] = {};
int ipt[128];

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> ipt[i];
    }
    for (int i = 0; i <= n + 1; i++)
    {
        lis[i] = 666;    
    }
    for (int i = 0; i < n; i++)
    {
        int *p = lower_bound(lis, lis + n, ipt[i]);
        rst[i] += p - lis + 1;
        *p = ipt[i];
    }
    for (int i = 0; i <= n + 1; i++)
    {
        lis[i] = 666;    
    }
    for (int i = n - 1; i >= 0; i--)
    {
        int *p = lower_bound(lis, lis + n, ipt[i]);
        rst[i] += p - lis + 1;
        *p = ipt[i];
    }
    int mx = 0;
    for (int i = 0; i < n; i++)
    {
        // cout << rst[i] << " ";
        mx = max(rst[i], mx);
    }
    cout << n - mx + 1;
    
    return 0;
}
